<#import "/admin/_layout.html" as layout>
<@layout.header "卡券编辑"></@layout.header>
<@layout.body>
    <div class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-left">
                        <li class="breadcrumb-item"><a href="#">卡券</a></li>
                        <li class="breadcrumb-item active">新增</li>
                    </ol>
                </div>
            </div>
        </div>
    </div>
    <section class="content">
        <div class="container-fluid">
            <div class="card card-default">
                <form id="myForm" method="POST" action="/admin/coupon/doSave" ok="/admin/coupon/list">
                    <input type="hidden" name="id" value="${(coupon.id)!}">
                    <div class="card-body">
                        <div class="form-group">
                            <label for="title">卡券名称</label>
                            <input type="text" name="title" class="form-control" id="title" placeholder="请输入卡券名称" value="${(coupon.title)!}">
                        </div>
                        <div class="form-group">
                            <label for="description">卡券描述</label>
                            <input type="text" name="description" class="form-control" id="description" placeholder="请输入卡券描述" value="${(coupon.description)!}">
                        </div>
                        <div class="form-group">
                            <#assign _type=(coupon.type)!1/>
                            <label for="type">类型</label>
                            <select class="form-control" id="type" name="type">
                                <option value="1" <@selectedIf value=(_type ==1)/>>满减券</option>
                                <option value="2" <@selectedIf value=(_type ==2)/>>叠加满减券</option>
                                <option value="3" <@selectedIf value=(_type ==3)/>>无门槛券</option>
                            </select>
                        </div>
                        <div class="box box-solid" style="width: 200px;">
                            <div class="box-header with-border ">
                                <label for="thumbnail">图标</label>
                            </div>
                            <div class="box-body no-padding">
                                <img src="/static/${(coupon.icon)!'/img/default.jpg'}"
                                     style="width: 100%;height: 200px"
                                     id="thumbnail">
                                <input type="hidden" value="${(coupon.icon)!}" name="icon" id="articleThumbnail">
                            </div>
                            <div class="box-footer">
                                <button type="button" class="btn-image-browser btn btn-default btn-sm "
                                        for-src="thumbnail"
                                        for-input="articleThumbnail">选择图片
                                </button>
                                <a href="javascript:;" style="padding-left: 15px" id="removeThumbnail">移除</a>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="amount">优惠券金额</label>
                            <input type="number" name="amount" class="form-control" id="amount" placeholder="请输入优惠券金额" value="${(coupon.amount)!}">
                        </div>
                        <div class="form-group">
                            <label for="quota">优惠券数量</label>
                            <input type="number" name="quota" class="form-control" id="quota" placeholder="请输入优惠券数量" value="${(coupon.quota)!}">
                        </div>
                        <div class="form-group">
                            <label for="withAmount">满多少可用</label>
                            <input type="number" name="withAmount" class="form-control" id="withAmount" placeholder="请输入满多少可用金额" value="${(coupon.withAmount)!}">
                        </div>
                        <div class="form-group">
                            <label for="withAward">是否推广券</label>
                            <input type="checkbox" class="switchery" data-for="withAward" <@checkedIf value=(coupon?? && coupon.withAward)/>>
                            <input type="hidden" id="withAward" name="withAward">
                            <p class="help-block">优惠券的拥有者可以把自己的优惠券给别人用，当优惠券被别人使用后，优惠券的拥有者可以获得奖励金额。 </p>
                        </div>
                        <div class="form-group">
                            <label for="awardAmount">消费后奖励金额</label>
                            <input type="number" name="awardAmount" class="form-control" id="awardAmount" placeholder="请输入消费后奖励金额" value="${(coupon.awardAmount)!}">
                        </div>

                        <div class="form-group">
                            <label for="withMember">是否只限会员可用</label>
                            <input type="checkbox" class="switchery" data-for="withMember" <@checkedIf value=(coupon?? && coupon.withMember)/>>
                            <input type="hidden" id="withMember" name="withMember">
                            <p class="help-block">必须是会员的用户才可以使用。 </p>
                        </div>
                        <div class="form-group">
                            <label for="withMulti">是否可以多次使用</label>
                            <input type="checkbox" class="switchery" data-for="withMulti" <@checkedIf value=(coupon?? && coupon.withMulti)/>>
                            <input type="hidden" id="withMulti" name="withMulti">
                            <p class="help-block">只要不过期，可以使用该优惠券多次购买产品。 </p>
                        </div>
                        <div class="form-group">
                            <label for="withOwner">只限领取人使用</label>
                            <input type="checkbox" class="switchery" data-for="withOwner" <@checkedIf value=(!coupon?? || coupon.withOwner)/>>
                            <input type="hidden" id="withOwner" name="withOwner">
                            <p class="help-block">只能是优惠券领取人可用，不能分享给其他人。 </p>
                        </div>

                        <div class="form-group">
                            <label for="validType">验证类型</label>
                            <select class="form-control" name="validType" id="validType">
                                <option value="1" <@selectedIf value=(coupon?? && coupon.validType == 1)/>>
                                    绝对时效（XXX ~ XXX时间段内有效）
                                </option>
                                <option value="2" <@selectedIf value=(coupon?? && coupon.validType == 2)/>>
                                    相对时效（领取后 X 天有效）
                                </option>
                            </select>
                        </div>

                        <div class="form-group" id="juedui">
                            <label for="validStartTime">绝对时效</label>
                            <input type="text" name="validStartTime" class="form-control jeegot-datetimepicker" value="<@formatTime value=(coupon.validStartTime)!/>"
                                           placeholder="">
                                    <div style="float: right;display: contents">
                                        至
                                    </div>
                                    <input type="text" name="validEndTime" class="form-control jeegot-datetimepicker" value="<@formatTime value=(coupon.validEndTime)!/>"
                                           placeholder="">
                        </div>

                        <div class="form-group" id="xiangdui">
                            <label for="validDays">相对时效</label>
                            <input type="number" name="validDays" class="form-control" id="validDays" placeholder="请输入有效天数" value="${(coupon.validDays)!}">
                            <p class="help-block">单位：天，用户领取优惠券后多少天内有效。 </p>
                        </div>

                        <div class="form-group">
                            <label class="control-label">状态</label>
                            <select class="form-control" name="status">
                                <option value="1" <@selectedIf value=(coupon?? && coupon.status == 1)/>>
                                    正常可用
                                </option>
                                <option value="0" <@selectedIf value=(coupon?? && coupon.status == 0)/>>
                                    失效
                                </option>
                            </select>
                            <p class="help-block">选择 失效 后，该优惠券下的所有券将会立即失效。 </p>
                        </div>

                    </div>
                    <div class="card-footer">
                        <button type="submit" class="btn btn-primary">提交</button>
                    </div>
                </form>
            </div>
        </div>
    </section>
</@layout.body>
<@layout.script>
    <script>
        $(function () {
            submitForm({
                title: { required: true},
                amount: { required: true},
                quota: { required: true},
                withAmount: { required: true},
            },{
                title: {required: "请输入卡券名称"},
                amount: {required: "请输入优惠券金额"},
                quota: {required: "请输入优惠券数量"},
                withAmount: {required: "请输入满减金额"},
            })
        });
    </script>
</@layout.script>